{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "shanghai = pd.read_excel(r'D:\\Programming\\Python\\PlayTogether_Data\\book3_pandas\\class11_specialPandas\\销量统计.xlsx', '上海销量', \n",
    "                         header = 1, index_col=0)\n",
    "# D:\\数据分析师\\Python"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>1月</th>\n",
       "      <th>2月</th>\n",
       "      <th>3月</th>\n",
       "      <th>4月</th>\n",
       "      <th>5月</th>\n",
       "      <th>6月</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>品名</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>按摩椅</th>\n",
       "      <td>104</td>\n",
       "      <td>177</td>\n",
       "      <td>189</td>\n",
       "      <td>156</td>\n",
       "      <td>121</td>\n",
       "      <td>126</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>针灸仪</th>\n",
       "      <td>146</td>\n",
       "      <td>131</td>\n",
       "      <td>179</td>\n",
       "      <td>193</td>\n",
       "      <td>190</td>\n",
       "      <td>125</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>诊疗仪</th>\n",
       "      <td>152</td>\n",
       "      <td>106</td>\n",
       "      <td>109</td>\n",
       "      <td>168</td>\n",
       "      <td>174</td>\n",
       "      <td>143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>消毒柜</th>\n",
       "      <td>178</td>\n",
       "      <td>130</td>\n",
       "      <td>189</td>\n",
       "      <td>164</td>\n",
       "      <td>133</td>\n",
       "      <td>156</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      1月   2月   3月   4月   5月   6月\n",
       "品名                               \n",
       "按摩椅  104  177  189  156  121  126\n",
       "针灸仪  146  131  179  193  190  125\n",
       "诊疗仪  152  106  109  168  174  143\n",
       "消毒柜  178  130  189  164  133  156"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "shanghai"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "品名\n",
       "按摩椅    177\n",
       "针灸仪    131\n",
       "诊疗仪    106\n",
       "消毒柜    130\n",
       "Name: 2月, dtype: int64"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "shanghai['2月']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1月    178\n",
       "2月    130\n",
       "3月    189\n",
       "4月    164\n",
       "5月    133\n",
       "6月    156\n",
       "Name: 消毒柜, dtype: int64"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "shanghai.loc['消毒柜']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1.灵活索引，按名对齐"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "shenzhen = pd.read_excel(r'D:\\Programming\\Python\\PlayTogether_Data\\book3_pandas\\class11_specialPandas\\销量统计.xlsx', '深圳销量', \n",
    "                         header = 1, index_col=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>1月</th>\n",
       "      <th>2月</th>\n",
       "      <th>3月</th>\n",
       "      <th>4月</th>\n",
       "      <th>5月</th>\n",
       "      <th>6月</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>品名</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>消毒柜</th>\n",
       "      <td>197</td>\n",
       "      <td>179</td>\n",
       "      <td>183</td>\n",
       "      <td>147</td>\n",
       "      <td>137</td>\n",
       "      <td>140</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>按摩椅</th>\n",
       "      <td>102</td>\n",
       "      <td>128</td>\n",
       "      <td>124</td>\n",
       "      <td>132</td>\n",
       "      <td>178</td>\n",
       "      <td>196</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>诊疗仪</th>\n",
       "      <td>138</td>\n",
       "      <td>115</td>\n",
       "      <td>175</td>\n",
       "      <td>152</td>\n",
       "      <td>189</td>\n",
       "      <td>142</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>针灸仪</th>\n",
       "      <td>160</td>\n",
       "      <td>123</td>\n",
       "      <td>132</td>\n",
       "      <td>170</td>\n",
       "      <td>183</td>\n",
       "      <td>172</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      1月   2月   3月   4月   5月   6月\n",
       "品名                               \n",
       "消毒柜  197  179  183  147  137  140\n",
       "按摩椅  102  128  124  132  178  196\n",
       "诊疗仪  138  115  175  152  189  142\n",
       "针灸仪  160  123  132  170  183  172"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "shenzhen"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>1月</th>\n",
       "      <th>2月</th>\n",
       "      <th>3月</th>\n",
       "      <th>4月</th>\n",
       "      <th>5月</th>\n",
       "      <th>6月</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>品名</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>按摩椅</th>\n",
       "      <td>206</td>\n",
       "      <td>305</td>\n",
       "      <td>313</td>\n",
       "      <td>288</td>\n",
       "      <td>299</td>\n",
       "      <td>322</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>消毒柜</th>\n",
       "      <td>375</td>\n",
       "      <td>309</td>\n",
       "      <td>372</td>\n",
       "      <td>311</td>\n",
       "      <td>270</td>\n",
       "      <td>296</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>诊疗仪</th>\n",
       "      <td>290</td>\n",
       "      <td>221</td>\n",
       "      <td>284</td>\n",
       "      <td>320</td>\n",
       "      <td>363</td>\n",
       "      <td>285</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>针灸仪</th>\n",
       "      <td>306</td>\n",
       "      <td>254</td>\n",
       "      <td>311</td>\n",
       "      <td>363</td>\n",
       "      <td>373</td>\n",
       "      <td>297</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      1月   2月   3月   4月   5月   6月\n",
       "品名                               \n",
       "按摩椅  206  305  313  288  299  322\n",
       "消毒柜  375  309  372  311  270  296\n",
       "诊疗仪  290  221  284  320  363  285\n",
       "针灸仪  306  254  311  363  373  297"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "shanghai + shenzhen\n",
    "# 自动按品名相加"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 2.时间序列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "transfer_cargo = pd.read_excel(r'D:\\Programming\\Python\\PlayTogether_Data\\book3_pandas\\class11_specialPandas\\销量统计.xlsx', '调货明细', \n",
    "                         index_col=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>品名</th>\n",
       "      <th>数量</th>\n",
       "      <th>接收单位</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>调货时间</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-01-03 00:00:00.000</th>\n",
       "      <td>按摩椅</td>\n",
       "      <td>2</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-03 04:51:26.541</th>\n",
       "      <td>诊疗仪</td>\n",
       "      <td>2</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-03 12:12:13.376</th>\n",
       "      <td>诊疗仪</td>\n",
       "      <td>1</td>\n",
       "      <td>深圳</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-03 17:10:35.188</th>\n",
       "      <td>针灸仪</td>\n",
       "      <td>1</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-04 05:10:55.707</th>\n",
       "      <td>诊疗仪</td>\n",
       "      <td>2</td>\n",
       "      <td>深圳</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-06-28 12:36:24.087</th>\n",
       "      <td>针灸仪</td>\n",
       "      <td>1</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-06-28 23:45:45.834</th>\n",
       "      <td>针灸仪</td>\n",
       "      <td>1</td>\n",
       "      <td>深圳</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-06-29 11:56:09.418</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>2</td>\n",
       "      <td>深圳</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-06-30 11:46:20.841</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>1</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-06-30 19:54:12.561</th>\n",
       "      <td>诊疗仪</td>\n",
       "      <td>2</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>367 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                          品名  数量 接收单位\n",
       "调货时间                                 \n",
       "2021-01-03 00:00:00.000  按摩椅   2   广州\n",
       "2021-01-03 04:51:26.541  诊疗仪   2   广州\n",
       "2021-01-03 12:12:13.376  诊疗仪   1   深圳\n",
       "2021-01-03 17:10:35.188  针灸仪   1   上海\n",
       "2021-01-04 05:10:55.707  诊疗仪   2   深圳\n",
       "...                      ...  ..  ...\n",
       "2021-06-28 12:36:24.087  针灸仪   1   上海\n",
       "2021-06-28 23:45:45.834  针灸仪   1   深圳\n",
       "2021-06-29 11:56:09.418  消毒柜   2   深圳\n",
       "2021-06-30 11:46:20.841  消毒柜   1   上海\n",
       "2021-06-30 19:54:12.561  诊疗仪   2   广州\n",
       "\n",
       "[367 rows x 3 columns]"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "transfer_cargo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>品名</th>\n",
       "      <th>数量</th>\n",
       "      <th>接收单位</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>调货时间</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-05-03 07:47:38.762</th>\n",
       "      <td>按摩椅</td>\n",
       "      <td>1</td>\n",
       "      <td>深圳</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-03 18:24:31.089</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>1</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-04 14:19:39.180</th>\n",
       "      <td>按摩椅</td>\n",
       "      <td>2</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-04 22:13:21.411</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>1</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-05 10:56:38.678</th>\n",
       "      <td>按摩椅</td>\n",
       "      <td>2</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-06-08 16:21:37.287</th>\n",
       "      <td>按摩椅</td>\n",
       "      <td>2</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-06-09 09:54:40.698</th>\n",
       "      <td>诊疗仪</td>\n",
       "      <td>1</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-06-10 00:21:33.911</th>\n",
       "      <td>按摩椅</td>\n",
       "      <td>1</td>\n",
       "      <td>深圳</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-06-10 05:19:51.578</th>\n",
       "      <td>按摩椅</td>\n",
       "      <td>1</td>\n",
       "      <td>深圳</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-06-10 21:42:26.406</th>\n",
       "      <td>按摩椅</td>\n",
       "      <td>2</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>77 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                          品名  数量 接收单位\n",
       "调货时间                                 \n",
       "2021-05-03 07:47:38.762  按摩椅   1   深圳\n",
       "2021-05-03 18:24:31.089  消毒柜   1   上海\n",
       "2021-05-04 14:19:39.180  按摩椅   2   上海\n",
       "2021-05-04 22:13:21.411  消毒柜   1   广州\n",
       "2021-05-05 10:56:38.678  按摩椅   2   上海\n",
       "...                      ...  ..  ...\n",
       "2021-06-08 16:21:37.287  按摩椅   2   广州\n",
       "2021-06-09 09:54:40.698  诊疗仪   1   广州\n",
       "2021-06-10 00:21:33.911  按摩椅   1   深圳\n",
       "2021-06-10 05:19:51.578  按摩椅   1   深圳\n",
       "2021-06-10 21:42:26.406  按摩椅   2   上海\n",
       "\n",
       "[77 rows x 3 columns]"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 按日期\n",
    "transfer_cargo['2021-5-3' : '2021-6-10']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>品名</th>\n",
       "      <th>数量</th>\n",
       "      <th>接收单位</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>调货时间</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-05-03 18:24:31.089</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>1</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-04 14:19:39.180</th>\n",
       "      <td>按摩椅</td>\n",
       "      <td>2</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-04 22:13:21.411</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>1</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-05 10:56:38.678</th>\n",
       "      <td>按摩椅</td>\n",
       "      <td>2</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-06 08:34:56.527</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>1</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-07 06:34:08.269</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>1</td>\n",
       "      <td>深圳</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-07 11:59:36.702</th>\n",
       "      <td>按摩椅</td>\n",
       "      <td>2</td>\n",
       "      <td>深圳</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-08 08:54:12.969</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>1</td>\n",
       "      <td>深圳</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-09 00:32:22.081</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>2</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-09 21:58:40.078</th>\n",
       "      <td>按摩椅</td>\n",
       "      <td>2</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-10 13:10:29.904</th>\n",
       "      <td>针灸仪</td>\n",
       "      <td>2</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-10 23:42:06.669</th>\n",
       "      <td>按摩椅</td>\n",
       "      <td>1</td>\n",
       "      <td>深圳</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-11 10:09:34.369</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>2</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-11 17:26:45.305</th>\n",
       "      <td>诊疗仪</td>\n",
       "      <td>2</td>\n",
       "      <td>深圳</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-12 14:34:39.391</th>\n",
       "      <td>按摩椅</td>\n",
       "      <td>2</td>\n",
       "      <td>深圳</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-13 05:58:21.272</th>\n",
       "      <td>诊疗仪</td>\n",
       "      <td>1</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-14 02:06:16.569</th>\n",
       "      <td>按摩椅</td>\n",
       "      <td>2</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-14 13:45:51.930</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>2</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-14 19:02:09.295</th>\n",
       "      <td>按摩椅</td>\n",
       "      <td>2</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-15 02:54:28.667</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>2</td>\n",
       "      <td>深圳</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                          品名  数量 接收单位\n",
       "调货时间                                 \n",
       "2021-05-03 18:24:31.089  消毒柜   1   上海\n",
       "2021-05-04 14:19:39.180  按摩椅   2   上海\n",
       "2021-05-04 22:13:21.411  消毒柜   1   广州\n",
       "2021-05-05 10:56:38.678  按摩椅   2   上海\n",
       "2021-05-06 08:34:56.527  消毒柜   1   广州\n",
       "2021-05-07 06:34:08.269  消毒柜   1   深圳\n",
       "2021-05-07 11:59:36.702  按摩椅   2   深圳\n",
       "2021-05-08 08:54:12.969  消毒柜   1   深圳\n",
       "2021-05-09 00:32:22.081  消毒柜   2   广州\n",
       "2021-05-09 21:58:40.078  按摩椅   2   广州\n",
       "2021-05-10 13:10:29.904  针灸仪   2   广州\n",
       "2021-05-10 23:42:06.669  按摩椅   1   深圳\n",
       "2021-05-11 10:09:34.369  消毒柜   2   上海\n",
       "2021-05-11 17:26:45.305  诊疗仪   2   深圳\n",
       "2021-05-12 14:34:39.391  按摩椅   2   深圳\n",
       "2021-05-13 05:58:21.272  诊疗仪   1   广州\n",
       "2021-05-14 02:06:16.569  按摩椅   2   上海\n",
       "2021-05-14 13:45:51.930  消毒柜   2   上海\n",
       "2021-05-14 19:02:09.295  按摩椅   2   广州\n",
       "2021-05-15 02:54:28.667  消毒柜   2   深圳"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 按时间\n",
    "transfer_cargo['2021-5-3 10:00' : '2021-5-15 7:00']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "<ipython-input-42-70c25cba5626>:2: UserWarning: Boolean Series key will be reindexed to match DataFrame index.\n",
      "  transfer_cargo['2021-5-3 10:00' : '2021-5-15 7:00'][transfer_cargo['品名']=='消毒柜']\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>品名</th>\n",
       "      <th>数量</th>\n",
       "      <th>接收单位</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>调货时间</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-05-03 18:24:31.089</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>1</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-04 22:13:21.411</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>1</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-06 08:34:56.527</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>1</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-07 06:34:08.269</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>1</td>\n",
       "      <td>深圳</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-08 08:54:12.969</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>1</td>\n",
       "      <td>深圳</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-09 00:32:22.081</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>2</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-11 10:09:34.369</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>2</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-14 13:45:51.930</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>2</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-15 02:54:28.667</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>2</td>\n",
       "      <td>深圳</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                          品名  数量 接收单位\n",
       "调货时间                                 \n",
       "2021-05-03 18:24:31.089  消毒柜   1   上海\n",
       "2021-05-04 22:13:21.411  消毒柜   1   广州\n",
       "2021-05-06 08:34:56.527  消毒柜   1   广州\n",
       "2021-05-07 06:34:08.269  消毒柜   1   深圳\n",
       "2021-05-08 08:54:12.969  消毒柜   1   深圳\n",
       "2021-05-09 00:32:22.081  消毒柜   2   广州\n",
       "2021-05-11 10:09:34.369  消毒柜   2   上海\n",
       "2021-05-14 13:45:51.930  消毒柜   2   上海\n",
       "2021-05-15 02:54:28.667  消毒柜   2   深圳"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 结合定位掩码\n",
    "transfer_cargo['2021-5-3 10:00' : '2021-5-15 7:00'][transfer_cargo['品名']=='消毒柜']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>品名</th>\n",
       "      <th>数量</th>\n",
       "      <th>接收单位</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>调货时间</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-01-03 00:00:00.000</th>\n",
       "      <td>按摩椅</td>\n",
       "      <td>2</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-07 00:18:16.245</th>\n",
       "      <td>按摩椅</td>\n",
       "      <td>2</td>\n",
       "      <td>深圳</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-11 00:03:57.984</th>\n",
       "      <td>按摩椅</td>\n",
       "      <td>2</td>\n",
       "      <td>深圳</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-23 00:26:36.383</th>\n",
       "      <td>诊疗仪</td>\n",
       "      <td>1</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-02-02 00:05:38.938</th>\n",
       "      <td>针灸仪</td>\n",
       "      <td>2</td>\n",
       "      <td>深圳</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-02-10 00:59:47.653</th>\n",
       "      <td>针灸仪</td>\n",
       "      <td>2</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-02-15 00:47:07.889</th>\n",
       "      <td>针灸仪</td>\n",
       "      <td>2</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-03-09 00:16:43.519</th>\n",
       "      <td>针灸仪</td>\n",
       "      <td>2</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-03-16 00:40:46.098</th>\n",
       "      <td>针灸仪</td>\n",
       "      <td>2</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-02 00:07:06.671</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>2</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-10 00:04:54.499</th>\n",
       "      <td>按摩椅</td>\n",
       "      <td>2</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-14 00:29:18.301</th>\n",
       "      <td>针灸仪</td>\n",
       "      <td>2</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-09 00:32:22.081</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>2</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-06-03 00:39:46.225</th>\n",
       "      <td>诊疗仪</td>\n",
       "      <td>2</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-06-10 00:21:33.911</th>\n",
       "      <td>按摩椅</td>\n",
       "      <td>1</td>\n",
       "      <td>深圳</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-06-27 00:28:37.010</th>\n",
       "      <td>诊疗仪</td>\n",
       "      <td>2</td>\n",
       "      <td>广州</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                          品名  数量 接收单位\n",
       "调货时间                                 \n",
       "2021-01-03 00:00:00.000  按摩椅   2   广州\n",
       "2021-01-07 00:18:16.245  按摩椅   2   深圳\n",
       "2021-01-11 00:03:57.984  按摩椅   2   深圳\n",
       "2021-01-23 00:26:36.383  诊疗仪   1   广州\n",
       "2021-02-02 00:05:38.938  针灸仪   2   深圳\n",
       "2021-02-10 00:59:47.653  针灸仪   2   上海\n",
       "2021-02-15 00:47:07.889  针灸仪   2   上海\n",
       "2021-03-09 00:16:43.519  针灸仪   2   广州\n",
       "2021-03-16 00:40:46.098  针灸仪   2   广州\n",
       "2021-04-02 00:07:06.671  消毒柜   2   广州\n",
       "2021-04-10 00:04:54.499  按摩椅   2   上海\n",
       "2021-04-14 00:29:18.301  针灸仪   2   上海\n",
       "2021-05-09 00:32:22.081  消毒柜   2   广州\n",
       "2021-06-03 00:39:46.225  诊疗仪   2   广州\n",
       "2021-06-10 00:21:33.911  按摩椅   1   深圳\n",
       "2021-06-27 00:28:37.010  诊疗仪   2   广州"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 所有0点调货的明细\n",
    "transfer_cargo[transfer_cargo.index.hour == 0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 分组\n",
    "summary_daily = transfer_cargo.groupby(transfer_cargo.index.date).agg(sum)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>数量</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-01-03</th>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-04</th>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-05</th>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-06</th>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-07</th>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-06-26</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-06-27</th>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-06-28</th>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-06-29</th>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-06-30</th>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>179 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            数量\n",
       "2021-01-03   6\n",
       "2021-01-04   4\n",
       "2021-01-05   3\n",
       "2021-01-06   2\n",
       "2021-01-07   4\n",
       "...         ..\n",
       "2021-06-26   1\n",
       "2021-06-27   4\n",
       "2021-06-28   2\n",
       "2021-06-29   2\n",
       "2021-06-30   3\n",
       "\n",
       "[179 rows x 1 columns]"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "summary_daily"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [],
   "source": [
    "summary_daily['3天平均调货量'] = summary_daily.rolling(3).mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>数量</th>\n",
       "      <th>3天平均调货量</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-01-03</th>\n",
       "      <td>6</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-04</th>\n",
       "      <td>4</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-05</th>\n",
       "      <td>3</td>\n",
       "      <td>4.333333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-06</th>\n",
       "      <td>2</td>\n",
       "      <td>3.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-07</th>\n",
       "      <td>4</td>\n",
       "      <td>3.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-06-26</th>\n",
       "      <td>1</td>\n",
       "      <td>2.333333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-06-27</th>\n",
       "      <td>4</td>\n",
       "      <td>3.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-06-28</th>\n",
       "      <td>2</td>\n",
       "      <td>2.333333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-06-29</th>\n",
       "      <td>2</td>\n",
       "      <td>2.666667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-06-30</th>\n",
       "      <td>3</td>\n",
       "      <td>2.333333</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>179 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            数量   3天平均调货量\n",
       "2021-01-03   6       NaN\n",
       "2021-01-04   4       NaN\n",
       "2021-01-05   3  4.333333\n",
       "2021-01-06   2  3.000000\n",
       "2021-01-07   4  3.000000\n",
       "...         ..       ...\n",
       "2021-06-26   1  2.333333\n",
       "2021-06-27   4  3.000000\n",
       "2021-06-28   2  2.333333\n",
       "2021-06-29   2  2.666667\n",
       "2021-06-30   3  2.333333\n",
       "\n",
       "[179 rows x 2 columns]"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "summary_daily"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {},
   "outputs": [],
   "source": [
    "duty = pd.read_excel(r'D:\\Programming\\Python\\PlayTogether_Data\\book3_pandas\\class11_specialPandas\\销量统计.xlsx', '值班记录', \n",
    "                         header=0, index_col=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>仓库地点</th>\n",
       "      <th>值班人员</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>值班日期</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-01-01</th>\n",
       "      <td>上海</td>\n",
       "      <td>李四</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-01</th>\n",
       "      <td>广州</td>\n",
       "      <td>王五</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-01</th>\n",
       "      <td>深圳</td>\n",
       "      <td>刘八</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-02</th>\n",
       "      <td>上海</td>\n",
       "      <td>张三</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-02</th>\n",
       "      <td>广州</td>\n",
       "      <td>王五</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-07-20</th>\n",
       "      <td>广州</td>\n",
       "      <td>王五</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-07-20</th>\n",
       "      <td>深圳</td>\n",
       "      <td>刘八</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-07-21</th>\n",
       "      <td>上海</td>\n",
       "      <td>李四</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-07-21</th>\n",
       "      <td>广州</td>\n",
       "      <td>赵六</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-07-21</th>\n",
       "      <td>深圳</td>\n",
       "      <td>田七</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>606 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           仓库地点 值班人员\n",
       "值班日期                \n",
       "2021-01-01   上海   李四\n",
       "2021-01-01   广州   王五\n",
       "2021-01-01   深圳   刘八\n",
       "2021-01-02   上海   张三\n",
       "2021-01-02   广州   王五\n",
       "...         ...  ...\n",
       "2021-07-20   广州   王五\n",
       "2021-07-20   深圳   刘八\n",
       "2021-07-21   上海   李四\n",
       "2021-07-21   广州   赵六\n",
       "2021-07-21   深圳   田七\n",
       "\n",
       "[606 rows x 2 columns]"
      ]
     },
     "execution_count": 110,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "duty"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>仓库地点</th>\n",
       "      <th>值班人员</th>\n",
       "      <th>日期</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>值班日期</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-01-01</th>\n",
       "      <td>上海</td>\n",
       "      <td>李四</td>\n",
       "      <td>2021-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-01</th>\n",
       "      <td>广州</td>\n",
       "      <td>王五</td>\n",
       "      <td>2021-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-01</th>\n",
       "      <td>深圳</td>\n",
       "      <td>刘八</td>\n",
       "      <td>2021-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-02</th>\n",
       "      <td>上海</td>\n",
       "      <td>张三</td>\n",
       "      <td>2021-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-02</th>\n",
       "      <td>广州</td>\n",
       "      <td>王五</td>\n",
       "      <td>2021-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-07-20</th>\n",
       "      <td>广州</td>\n",
       "      <td>王五</td>\n",
       "      <td>2021-07-20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-07-20</th>\n",
       "      <td>深圳</td>\n",
       "      <td>刘八</td>\n",
       "      <td>2021-07-20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-07-21</th>\n",
       "      <td>上海</td>\n",
       "      <td>李四</td>\n",
       "      <td>2021-07-21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-07-21</th>\n",
       "      <td>广州</td>\n",
       "      <td>赵六</td>\n",
       "      <td>2021-07-21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-07-21</th>\n",
       "      <td>深圳</td>\n",
       "      <td>田七</td>\n",
       "      <td>2021-07-21</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>606 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           仓库地点 值班人员          日期\n",
       "值班日期                            \n",
       "2021-01-01   上海   李四  2021-01-01\n",
       "2021-01-01   广州   王五  2021-01-01\n",
       "2021-01-01   深圳   刘八  2021-01-01\n",
       "2021-01-02   上海   张三  2021-01-02\n",
       "2021-01-02   广州   王五  2021-01-02\n",
       "...         ...  ...         ...\n",
       "2021-07-20   广州   王五  2021-07-20\n",
       "2021-07-20   深圳   刘八  2021-07-20\n",
       "2021-07-21   上海   李四  2021-07-21\n",
       "2021-07-21   广州   赵六  2021-07-21\n",
       "2021-07-21   深圳   田七  2021-07-21\n",
       "\n",
       "[606 rows x 3 columns]"
      ]
     },
     "execution_count": 111,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "duty['日期'] = duty.index.date\n",
    "duty"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>品名</th>\n",
       "      <th>数量</th>\n",
       "      <th>接收单位</th>\n",
       "      <th>日期</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>调货时间</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-01-03 00:00:00.000</th>\n",
       "      <td>按摩椅</td>\n",
       "      <td>2</td>\n",
       "      <td>广州</td>\n",
       "      <td>2021-01-03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-03 04:51:26.541</th>\n",
       "      <td>诊疗仪</td>\n",
       "      <td>2</td>\n",
       "      <td>广州</td>\n",
       "      <td>2021-01-03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-03 12:12:13.376</th>\n",
       "      <td>诊疗仪</td>\n",
       "      <td>1</td>\n",
       "      <td>深圳</td>\n",
       "      <td>2021-01-03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-03 17:10:35.188</th>\n",
       "      <td>针灸仪</td>\n",
       "      <td>1</td>\n",
       "      <td>上海</td>\n",
       "      <td>2021-01-03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-04 05:10:55.707</th>\n",
       "      <td>诊疗仪</td>\n",
       "      <td>2</td>\n",
       "      <td>深圳</td>\n",
       "      <td>2021-01-04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-06-28 12:36:24.087</th>\n",
       "      <td>针灸仪</td>\n",
       "      <td>1</td>\n",
       "      <td>上海</td>\n",
       "      <td>2021-06-28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-06-28 23:45:45.834</th>\n",
       "      <td>针灸仪</td>\n",
       "      <td>1</td>\n",
       "      <td>深圳</td>\n",
       "      <td>2021-06-28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-06-29 11:56:09.418</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>2</td>\n",
       "      <td>深圳</td>\n",
       "      <td>2021-06-29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-06-30 11:46:20.841</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>1</td>\n",
       "      <td>上海</td>\n",
       "      <td>2021-06-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-06-30 19:54:12.561</th>\n",
       "      <td>诊疗仪</td>\n",
       "      <td>2</td>\n",
       "      <td>广州</td>\n",
       "      <td>2021-06-30</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>367 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                          品名  数量 接收单位          日期\n",
       "调货时间                                             \n",
       "2021-01-03 00:00:00.000  按摩椅   2   广州  2021-01-03\n",
       "2021-01-03 04:51:26.541  诊疗仪   2   广州  2021-01-03\n",
       "2021-01-03 12:12:13.376  诊疗仪   1   深圳  2021-01-03\n",
       "2021-01-03 17:10:35.188  针灸仪   1   上海  2021-01-03\n",
       "2021-01-04 05:10:55.707  诊疗仪   2   深圳  2021-01-04\n",
       "...                      ...  ..  ...         ...\n",
       "2021-06-28 12:36:24.087  针灸仪   1   上海  2021-06-28\n",
       "2021-06-28 23:45:45.834  针灸仪   1   深圳  2021-06-28\n",
       "2021-06-29 11:56:09.418  消毒柜   2   深圳  2021-06-29\n",
       "2021-06-30 11:46:20.841  消毒柜   1   上海  2021-06-30\n",
       "2021-06-30 19:54:12.561  诊疗仪   2   广州  2021-06-30\n",
       "\n",
       "[367 rows x 4 columns]"
      ]
     },
     "execution_count": 112,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "transfer_cargo['日期'] = transfer_cargo.index.date\n",
    "transfer_cargo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 连接\n",
    "linked_record = pd.merge(transfer_cargo, duty, left_on=['日期', '接收单位'], right_on=['日期', '仓库地点'], how='left')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>品名</th>\n",
       "      <th>数量</th>\n",
       "      <th>接收单位</th>\n",
       "      <th>日期</th>\n",
       "      <th>仓库地点</th>\n",
       "      <th>值班人员</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>按摩椅</td>\n",
       "      <td>2</td>\n",
       "      <td>广州</td>\n",
       "      <td>2021-01-03</td>\n",
       "      <td>广州</td>\n",
       "      <td>赵六</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>诊疗仪</td>\n",
       "      <td>2</td>\n",
       "      <td>广州</td>\n",
       "      <td>2021-01-03</td>\n",
       "      <td>广州</td>\n",
       "      <td>赵六</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>诊疗仪</td>\n",
       "      <td>1</td>\n",
       "      <td>深圳</td>\n",
       "      <td>2021-01-03</td>\n",
       "      <td>深圳</td>\n",
       "      <td>田七</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>针灸仪</td>\n",
       "      <td>1</td>\n",
       "      <td>上海</td>\n",
       "      <td>2021-01-03</td>\n",
       "      <td>上海</td>\n",
       "      <td>张三</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>诊疗仪</td>\n",
       "      <td>2</td>\n",
       "      <td>深圳</td>\n",
       "      <td>2021-01-04</td>\n",
       "      <td>深圳</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>362</th>\n",
       "      <td>针灸仪</td>\n",
       "      <td>1</td>\n",
       "      <td>上海</td>\n",
       "      <td>2021-06-28</td>\n",
       "      <td>上海</td>\n",
       "      <td>李四</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>363</th>\n",
       "      <td>针灸仪</td>\n",
       "      <td>1</td>\n",
       "      <td>深圳</td>\n",
       "      <td>2021-06-28</td>\n",
       "      <td>深圳</td>\n",
       "      <td>田七</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>364</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>2</td>\n",
       "      <td>深圳</td>\n",
       "      <td>2021-06-29</td>\n",
       "      <td>深圳</td>\n",
       "      <td>刘八</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>365</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>1</td>\n",
       "      <td>上海</td>\n",
       "      <td>2021-06-30</td>\n",
       "      <td>上海</td>\n",
       "      <td>李四</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>366</th>\n",
       "      <td>诊疗仪</td>\n",
       "      <td>2</td>\n",
       "      <td>广州</td>\n",
       "      <td>2021-06-30</td>\n",
       "      <td>广州</td>\n",
       "      <td>赵六</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>367 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      品名  数量 接收单位          日期 仓库地点 值班人员\n",
       "0    按摩椅   2   广州  2021-01-03   广州   赵六\n",
       "1    诊疗仪   2   广州  2021-01-03   广州   赵六\n",
       "2    诊疗仪   1   深圳  2021-01-03   深圳   田七\n",
       "3    针灸仪   1   上海  2021-01-03   上海   张三\n",
       "4    诊疗仪   2   深圳  2021-01-04   深圳  NaN\n",
       "..   ...  ..  ...         ...  ...  ...\n",
       "362  针灸仪   1   上海  2021-06-28   上海   李四\n",
       "363  针灸仪   1   深圳  2021-06-28   深圳   田七\n",
       "364  消毒柜   2   深圳  2021-06-29   深圳   刘八\n",
       "365  消毒柜   1   上海  2021-06-30   上海   李四\n",
       "366  诊疗仪   2   广州  2021-06-30   广州   赵六\n",
       "\n",
       "[367 rows x 6 columns]"
      ]
     },
     "execution_count": 114,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "linked_record"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>品名</th>\n",
       "      <th>数量</th>\n",
       "      <th>接收单位</th>\n",
       "      <th>日期</th>\n",
       "      <th>仓库地点</th>\n",
       "      <th>值班人员</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>诊疗仪</td>\n",
       "      <td>2</td>\n",
       "      <td>深圳</td>\n",
       "      <td>2021-01-04</td>\n",
       "      <td>深圳</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>91</th>\n",
       "      <td>针灸仪</td>\n",
       "      <td>1</td>\n",
       "      <td>深圳</td>\n",
       "      <td>2021-02-11</td>\n",
       "      <td>深圳</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>147</th>\n",
       "      <td>诊疗仪</td>\n",
       "      <td>2</td>\n",
       "      <td>广州</td>\n",
       "      <td>2021-03-13</td>\n",
       "      <td>广州</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>215</th>\n",
       "      <td>针灸仪</td>\n",
       "      <td>2</td>\n",
       "      <td>上海</td>\n",
       "      <td>2021-04-13</td>\n",
       "      <td>上海</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>222</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>2</td>\n",
       "      <td>深圳</td>\n",
       "      <td>2021-04-17</td>\n",
       "      <td>深圳</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      品名  数量 接收单位          日期 仓库地点 值班人员\n",
       "4    诊疗仪   2   深圳  2021-01-04   深圳  NaN\n",
       "91   针灸仪   1   深圳  2021-02-11   深圳  NaN\n",
       "147  诊疗仪   2   广州  2021-03-13   广州  NaN\n",
       "215  针灸仪   2   上海  2021-04-13   上海  NaN\n",
       "222  消毒柜   2   深圳  2021-04-17   深圳  NaN"
      ]
     },
     "execution_count": 129,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 4.缺失值处理\n",
    "linked_record[pd.isnull(linked_record['值班人员'])]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       赵六\n",
       "1       赵六\n",
       "2       田七\n",
       "3       张三\n",
       "4      待调查\n",
       "      ... \n",
       "362     李四\n",
       "363     田七\n",
       "364     刘八\n",
       "365     李四\n",
       "366     赵六\n",
       "Name: 值班人员, Length: 367, dtype: object"
      ]
     },
     "execution_count": 130,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "linked_record['值班人员'].fillna('待调查')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>品名</th>\n",
       "      <th>数量</th>\n",
       "      <th>接收单位</th>\n",
       "      <th>日期</th>\n",
       "      <th>仓库地点</th>\n",
       "      <th>值班人员</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>按摩椅</td>\n",
       "      <td>2</td>\n",
       "      <td>广州</td>\n",
       "      <td>2021-01-03</td>\n",
       "      <td>广州</td>\n",
       "      <td>赵六</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>诊疗仪</td>\n",
       "      <td>2</td>\n",
       "      <td>广州</td>\n",
       "      <td>2021-01-03</td>\n",
       "      <td>广州</td>\n",
       "      <td>赵六</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>诊疗仪</td>\n",
       "      <td>1</td>\n",
       "      <td>深圳</td>\n",
       "      <td>2021-01-03</td>\n",
       "      <td>深圳</td>\n",
       "      <td>田七</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>针灸仪</td>\n",
       "      <td>1</td>\n",
       "      <td>上海</td>\n",
       "      <td>2021-01-03</td>\n",
       "      <td>上海</td>\n",
       "      <td>张三</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>诊疗仪</td>\n",
       "      <td>2</td>\n",
       "      <td>深圳</td>\n",
       "      <td>2021-01-04</td>\n",
       "      <td>深圳</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>362</th>\n",
       "      <td>针灸仪</td>\n",
       "      <td>1</td>\n",
       "      <td>上海</td>\n",
       "      <td>2021-06-28</td>\n",
       "      <td>上海</td>\n",
       "      <td>李四</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>363</th>\n",
       "      <td>针灸仪</td>\n",
       "      <td>1</td>\n",
       "      <td>深圳</td>\n",
       "      <td>2021-06-28</td>\n",
       "      <td>深圳</td>\n",
       "      <td>田七</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>364</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>2</td>\n",
       "      <td>深圳</td>\n",
       "      <td>2021-06-29</td>\n",
       "      <td>深圳</td>\n",
       "      <td>刘八</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>365</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>1</td>\n",
       "      <td>上海</td>\n",
       "      <td>2021-06-30</td>\n",
       "      <td>上海</td>\n",
       "      <td>李四</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>366</th>\n",
       "      <td>诊疗仪</td>\n",
       "      <td>2</td>\n",
       "      <td>广州</td>\n",
       "      <td>2021-06-30</td>\n",
       "      <td>广州</td>\n",
       "      <td>赵六</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>367 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      品名  数量 接收单位          日期 仓库地点 值班人员\n",
       "0    按摩椅   2   广州  2021-01-03   广州   赵六\n",
       "1    诊疗仪   2   广州  2021-01-03   广州   赵六\n",
       "2    诊疗仪   1   深圳  2021-01-03   深圳   田七\n",
       "3    针灸仪   1   上海  2021-01-03   上海   张三\n",
       "4    诊疗仪   2   深圳  2021-01-04   深圳  NaN\n",
       "..   ...  ..  ...         ...  ...  ...\n",
       "362  针灸仪   1   上海  2021-06-28   上海   李四\n",
       "363  针灸仪   1   深圳  2021-06-28   深圳   田七\n",
       "364  消毒柜   2   深圳  2021-06-29   深圳   刘八\n",
       "365  消毒柜   1   上海  2021-06-30   上海   李四\n",
       "366  诊疗仪   2   广州  2021-06-30   广州   赵六\n",
       "\n",
       "[367 rows x 6 columns]"
      ]
     },
     "execution_count": 132,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 看起来，并没替换？\n",
    "linked_record"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>品名</th>\n",
       "      <th>数量</th>\n",
       "      <th>接收单位</th>\n",
       "      <th>日期</th>\n",
       "      <th>仓库地点</th>\n",
       "      <th>值班人员</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>诊疗仪</td>\n",
       "      <td>2</td>\n",
       "      <td>深圳</td>\n",
       "      <td>2021-01-04</td>\n",
       "      <td>深圳</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>91</th>\n",
       "      <td>针灸仪</td>\n",
       "      <td>1</td>\n",
       "      <td>深圳</td>\n",
       "      <td>2021-02-11</td>\n",
       "      <td>深圳</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>147</th>\n",
       "      <td>诊疗仪</td>\n",
       "      <td>2</td>\n",
       "      <td>广州</td>\n",
       "      <td>2021-03-13</td>\n",
       "      <td>广州</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>215</th>\n",
       "      <td>针灸仪</td>\n",
       "      <td>2</td>\n",
       "      <td>上海</td>\n",
       "      <td>2021-04-13</td>\n",
       "      <td>上海</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>222</th>\n",
       "      <td>消毒柜</td>\n",
       "      <td>2</td>\n",
       "      <td>深圳</td>\n",
       "      <td>2021-04-17</td>\n",
       "      <td>深圳</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      品名  数量 接收单位          日期 仓库地点 值班人员\n",
       "4    诊疗仪   2   深圳  2021-01-04   深圳  NaN\n",
       "91   针灸仪   1   深圳  2021-02-11   深圳  NaN\n",
       "147  诊疗仪   2   广州  2021-03-13   广州  NaN\n",
       "215  针灸仪   2   上海  2021-04-13   上海  NaN\n",
       "222  消毒柜   2   深圳  2021-04-17   深圳  NaN"
      ]
     },
     "execution_count": 134,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 确实没fill\n",
    "linked_record[pd.isnull(linked_record['值班人员'])]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 138,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>品名</th>\n",
       "      <th>数量</th>\n",
       "      <th>接收单位</th>\n",
       "      <th>日期</th>\n",
       "      <th>仓库地点</th>\n",
       "      <th>值班人员</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>诊疗仪</td>\n",
       "      <td>2</td>\n",
       "      <td>广州</td>\n",
       "      <td>2021-01-03</td>\n",
       "      <td>广州</td>\n",
       "      <td>赵六</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>诊疗仪</td>\n",
       "      <td>1</td>\n",
       "      <td>深圳</td>\n",
       "      <td>2021-01-03</td>\n",
       "      <td>深圳</td>\n",
       "      <td>田七</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>针灸仪</td>\n",
       "      <td>1</td>\n",
       "      <td>上海</td>\n",
       "      <td>2021-01-03</td>\n",
       "      <td>上海</td>\n",
       "      <td>张三</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>诊疗仪</td>\n",
       "      <td>2</td>\n",
       "      <td>深圳</td>\n",
       "      <td>2021-01-04</td>\n",
       "      <td>深圳</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>针灸仪</td>\n",
       "      <td>2</td>\n",
       "      <td>广州</td>\n",
       "      <td>2021-01-04</td>\n",
       "      <td>广州</td>\n",
       "      <td>赵六</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>358</th>\n",
       "      <td>针灸仪</td>\n",
       "      <td>2</td>\n",
       "      <td>上海</td>\n",
       "      <td>2021-06-25</td>\n",
       "      <td>上海</td>\n",
       "      <td>李四</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>360</th>\n",
       "      <td>诊疗仪</td>\n",
       "      <td>2</td>\n",
       "      <td>广州</td>\n",
       "      <td>2021-06-27</td>\n",
       "      <td>广州</td>\n",
       "      <td>王五</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>362</th>\n",
       "      <td>针灸仪</td>\n",
       "      <td>1</td>\n",
       "      <td>上海</td>\n",
       "      <td>2021-06-28</td>\n",
       "      <td>上海</td>\n",
       "      <td>李四</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>363</th>\n",
       "      <td>针灸仪</td>\n",
       "      <td>1</td>\n",
       "      <td>深圳</td>\n",
       "      <td>2021-06-28</td>\n",
       "      <td>深圳</td>\n",
       "      <td>田七</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>366</th>\n",
       "      <td>诊疗仪</td>\n",
       "      <td>2</td>\n",
       "      <td>广州</td>\n",
       "      <td>2021-06-30</td>\n",
       "      <td>广州</td>\n",
       "      <td>赵六</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>183 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      品名  数量 接收单位          日期 仓库地点 值班人员\n",
       "1    诊疗仪   2   广州  2021-01-03   广州   赵六\n",
       "2    诊疗仪   1   深圳  2021-01-03   深圳   田七\n",
       "3    针灸仪   1   上海  2021-01-03   上海   张三\n",
       "4    诊疗仪   2   深圳  2021-01-04   深圳  NaN\n",
       "5    针灸仪   2   广州  2021-01-04   广州   赵六\n",
       "..   ...  ..  ...         ...  ...  ...\n",
       "358  针灸仪   2   上海  2021-06-25   上海   李四\n",
       "360  诊疗仪   2   广州  2021-06-27   广州   王五\n",
       "362  针灸仪   1   上海  2021-06-28   上海   李四\n",
       "363  针灸仪   1   深圳  2021-06-28   深圳   田七\n",
       "366  诊疗仪   2   广州  2021-06-30   广州   赵六\n",
       "\n",
       "[183 rows x 6 columns]"
      ]
     },
     "execution_count": 138,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 5.文本处理（使用正则式）：所有“仪”\n",
    "linked_record[linked_record['品名'].str.match(r'\\w+仪')]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
